import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wanxiang_app/bean/normal_entity.dart';
import 'package:wanxiang_app/bean/qa_list_entity.dart';
import 'package:wanxiang_app/pages/home/qaDetail.dart';
import 'package:wanxiang_app/utils/constant.dart';
import '../../bean/service_list_entity.dart';
import '../../utils/network_manager.dart';
import '../../utils/network_url.dart';
import '../../utils/toast_util.dart';
import '../../widgets/myappbar.dart';
import 'package:get/get.dart';

import 'noticeDetail.dart';

class NoticeController extends GetxController{

  @override
  void onInit() {
    super.onInit();
    _getService();
  }
  @override
  void onClose() {
    super.onClose();
  }
  List<QaListData> list = [];
  void _getService(){
    DioManager.getInstance().post(ServiceUrl.noticeList,null, (data) async {
      QaListEntity bannerEntity = QaListEntity.fromJson(jsonDecode(data));
      list = bannerEntity.data;
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }
}


class NoticePage extends GetView<NoticeController>  {
  late NoticeController controller ;
  late BuildContext context ;
  @override
  Widget build(BuildContext context1) {
    Get.lazyPut<NoticeController>(() => NoticeController());
    controller = Get.find();
    context = context1;

    return GetBuilder<NoticeController>(
      builder: (_){
        return  Scaffold(
            appBar: MyAppBar(context: context, title: '平台公告',hasLeading: true,),
            backgroundColor: Colors.white,
            body: controller.list.isEmpty?Container(): _content());
      },
    )
    ;

  }
  Widget _content(){
    return SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.only(left: 20.w,top: 20.h,right: 20.w,bottom: 20.h),
          child: Column(
            children: _all(),
          ),
        )
    ) ;
  }


  List<Widget> _all(){
    List<Widget> aa = [];
    controller.list.forEach((element) {
      aa.add(_item(element));
    });
    return aa;
  }

  Widget _item(item){
    return InkWell(
        onTap: (){
          Get.to(()=>NoticeDetailPage(),arguments: item.id.toString(),preventDuplicates:false);
        },
        child: Container(
          height: 71.h,
          decoration: BoxDecoration(
              border: Border(
                  bottom: BorderSide(width: 1.h,color: Color(0xFFF5F5F5))
              )
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(item.title),
              Image.asset(Constant.IMG_BASE+'arrow_right.png',width: 6.w,height: 11.h,)
            ],
          ),
        )
    ) ;
  }



}